<template>
  <div>
    <Spin :spinning="loading" tip="Loading...">
      <div style="padding-top: 1rem"></div>
      <!-- table -->
      <FormPanel ref="formPanel" :list="formList" :cols="1" :formType="'add'" labelWidth="100" :isSubmitBtn="false" @formChange="formChangeHandle" />
      <div style="padding-top: 1rem"></div>
      <div
        :style="{
          position: 'absolute',
          left: 0,
          right: 0,
          zIndex: 9,
          borderTop: '1px solid #e9e9e9',
          padding: '10px 20px',
          background: '#fff',
          textAlign: 'right',
        }"
      >
        <multiuse-button type="primary" :click="saveDialog.bind(this)">保 存</multiuse-button>
        <multiuse-button @click="closeDialog">关 闭</multiuse-button>
      </div>
    </Spin>
  </div>
</template>
<script>
import { newSave } from '@/api/claim/factory/ClaimCheckReasonMaintain';
import { getPartType } from '@/api/dictionary/index.js';

export default {
  data() {
    return {
      dataList1: [],
      visible: false,
      visibleDrawer: false,
      collapse: false,
      infoId: null,
      flterValue: {}, //参数
      fetchParams: {}, //ipa 接口
      selectedRows: [], //选中经销商
      formList: this.createFormList1(),
      saveData: null,
      activeName: '审核记录',
      loading: false,
    };
  },
  created() {
    this.chuqi();
    this.chuqi2();
  },
  methods: {
    formChangeHandle(val) {
      console.log(val);
      this.saveData = val;
    },
    //保存
    async saveDialog() {
      this.$refs.formPanel.SUBMIT_FORM();
      if (this.saveData) {
        this.loading = true;
        let res = await newSave(this.saveData);
        console.log(res);
        if (res.resultCode === 200) {
          this.$emit('save');
          return this.$notify.success({ title: '提示信息', message: '保存成功' });
        } else {
          // this.$notify.error({title: '提示信息', message: res.errMsg || '保存失败!'});
          // this.closeDialog();
          this.loading = false;
        }
      }
    },
    //取消操作
    closeDialog() {
      this.$emit('close', { visible: false, data: this.selectedRows, type: 'close' });
    },
    chooseOrderNo() {
      this.visible = true;
    },
    add() {},
    async chuqi() {
      const res = await getPartType({ type: 5582 });
      if (res.resultCode == 200) {
        this.formList.find((x) => x.fieldName == 'reasonType').itemList = res.data.map((y) => ({ text: y.codeCnDesc, value: y.codeId }));
      }
    },
    async chuqi2() {
      const res = await getPartType({ type: 5583 });
      if (res.resultCode == 200) {
        this.formList.find((x) => x.fieldName == 'reasonCol').itemList = res.data.map((y) => ({ text: y.codeCnDesc, value: y.codeId }));
      }
    },
    createFormList1() {
      return [
        {
          type: 'SELECT',
          label: '单据类型',
          fieldName: 'reasonType',
          placeholder: '请选择单据类型...',
          itemList: [],
          filterable: true,
          rules: [{ required: true, message: '请选择单据类型...', trigger: 'change' }],
        },
        {
          type: 'SELECT',
          label: '索赔字段',
          fieldName: 'reasonCol',
          itemList: [],
          placeholder: '请选择索赔字段...',
          filterable: true,
          rules: [{ required: true, message: '请选择索赔字段...', trigger: 'change' }],
        },
        {
          type: 'SELECT',
          label: '状态',
          fieldName: 'reasonStatus',
          placeholder: '请选择状态...',
          filterable: true,
          itemList: [
            { text: '启用', value: 1 },
            { text: '禁用', value: 0 },
          ],
          rules: [{ required: true, message: '请选择状态...', trigger: 'change' }],
        },
        {
          type: 'TEXT_AREA',
          label: '审核原因',
          fieldName: 'reasonRemarks',
          placeholder: '请输入审核原因...',
          rows: 2,
          rules: [{ required: true, message: '请输入审核原因...', trigger: 'blur' }],
        },
      ];
    },
  },
};
</script>

<style lang="less" scoped></style>
